<template>
	<view class="category-orders">
		<!-- <van-dropdown-menu>
			<van-dropdown-item :value="value1" :options="option1" />
			<van-dropdown-item :value="value2" :options="option2" />
		</van-dropdown-menu> -->
		<!-- <view class="con-3 ">
			<view class="con-3_left ">{{itemChooselist.venue_name}}</view>
			<view class="con-3_right " @click="show_no">切换</view>
		</view> -->
		<view class="con-1">
			<nav-bar title="分类订单" color="white" bg="rgba(0,0,0,0)"></nav-bar>
			<view class="bg">
				<view class="address">
					<view class="flex-space-between">
						<view class="flex-align">
							<van-image v-if="itemChooselist.venue_thumb != ''" width="74rpx" height="74rpx" radius="2"
								style="margin-right: 10rpx;" :src="itemChooselist.venue_thumb" />
							<van-image v-else width="74rpx" height="74rpx" radius="10rpx" fit="cover" style="margin-right: 10rpx;" src="https://img.yzcdn.cn/vant/cat.jpeg" />
							<view>
								<view class="address-name">{{itemChooselist.venue_name}}</view>
								<view class="address-desc">地址:{{itemChooselist.address}}</view>
							</view>
						</view>
						<view class="exchange flex-center flex-column " @click="show_no">
							<van-icon name="exchange" size="16" />
							切换
						</view>
					</view>
				</view>
			</view>

		</view>
		<van-row class="dates text-center">
			<van-col v-for="item in dates" :key="item.value" :span="6">
				<view class="date-item" :class="{ active: dateActive === item.value }" @click="dataslist(item)">
					{{ item.label }}
				</view>
			</van-col>
		</van-row>
		<view class="data-stat">

			<van-row :gutter="15">
				<van-col :span="8">
					<view class="box flex-center flex-column">
						<view class="value">{{total_num}}</view>
						<view class="label">总订单量</view>
					</view>
				</van-col>
				<van-col :span="8">
					<view class="box flex-center flex-column">
						<view class="value">{{complete_num}}</view>
						<view class="label">已付款订单</view>
					</view>
				</van-col>
				<van-col :span="8">
					<view class="box flex-center flex-column">
						<view class="value">{{after_sale_num}}</view>
						<view class="label">售后订单</view>
					</view>
				</van-col>
			</van-row>
		</view>

		<view style="width: 100%; height: 60rpx;background-color: #f8f8f8;margin-top: 20rpx;">
			<view style="float: left;">
				<image style="width: 32rpx;height: 32rpx;margin-top: 15rpx;margin-left: 30rpx;"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/dbe7a7371520f7585b4a83558336c24acbace2cc.png"
					mode=""></image>
			</view>
			<view style="float: left;line-height: 60rpx;font-size: 28rpx;color: #aaaaaa;margin-left: 20rpx;">
				数据仅供参考，以后台财务数据为准
			</view>
		</view>

		<view class="title">订单类型分析</view>
		<view v-show="showlist">
			<qiun-data-charts type="ring" :opts="ringopts" :chartData="pieChartData" />
		</view>
		<view>
		</view>

		<v-gap color="rgb(248,248,248)" />

		<view class="title">热销商品排名</view>
		<view class="table text-center">
			<view class="thead">
				<view class="tr d-flex">
					<view class="th">产品名称</view>
					<view class="th">产品分类</view>
					<view class="th">订单数</view>
					<!-- <view class="th">成交数</view> -->
					<!-- <view class="th">转化率</view> -->
				</view>
			</view>
			<view class="tbody">
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="list-2">
					<view class="tr d-flex" v-for="(item, index) in tableData" :key="index">
						<view class="td ellipsis-2 flex-center">
							<!-- <van-image width="60rpx" height="60rpx" /> -->
							{{ item.goods_name }}
						</view>
						<view class="td ellipsis-1 flex-center">{{ item.type_name }}</view>
						<view class="td ellipsis-1 flex-center">{{ item.sale_num }}</view>
						<!-- <view class="td ellipsis-1 flex-center">{{ item.d }}</view> -->
					</view>
				</scroll-view>
			</view>
		</view>
		<van-popup closeable :show="show" round position="bottom" @close="showclose">
			<view class="good-box">
				<view class="title">
					切换场馆
				</view>
				<view class="good-list">
					<!-- <van-radio-group :value="radio" @change="onChange"> -->
					<view class="good-item" v-for="(item,index) in venuelist" :key="index" @click="onChangelist(item)">
						<!-- <van-radio :name="index" :value="index" color="#2f75fa"
								:checked="index == 0 ? true : false"> -->
						<view class="flex-align">
							<van-image width="124rpx" height="124rpx" radius="10rpx" fit="cover"
								v-if="item.venue_thumb != ''" :src="item.venue_thumb" />
							<van-image v-else width="124rpx" height="124rpx" radius="10rpx" fit="cover"
								src="https://img.yzcdn.cn/vant/cat.jpeg" />
							<view class="info">
								<view class="name">{{item.venue_name}}</view>
								<view class="flex-align" v-if="item.project_list != ''">
									<view class="tag" v-if="item.project_list[0].name != ''">
										{{item.project_list[0].name}}
									</view>
									<view class="tag" v-if="item.project_list[1].name != '' && item.project_list[1]">
										{{item.project_list[1].name}}
									</view>
									<view class="tag" v-if="item.project_list[2].name != ''&& item.project_list[2]">
										{{item.project_list[2].name}}
									</view>
								</view>
								<view class="address">{{item.address}}</view>
							</view>
						</view>
						<!-- </van-radio> -->
					</view>
					<!-- </van-radio-group> -->
				</view>

				<!-- <view class="footer">
					<view class="btn" @click="queren">确认</view>
				</view> -->
			</view>
		</van-popup>
	</view>
</template>

<script>
	const personal = require("@/api/personal/index.js");
	export default {
		data() {
			return {
				ringopts: {
					"title": {
						"name": "订单数",
						"fontSize": 10,
						"color": "#b5b5b5"
					},
					"subtitle": {
						"name": "",
						"fontSize": 10,
						"color": "#b5b5b5"
					},
					color: ['rgb(230,148,148)', 'rgb(82,222,151)', 'rgb(241,201,176)', 'rgb(81,200,194)',
						'rgb(241,237,153)', 'rgb(178,154,228)', 'rgb(245,225,153)', 'rgb(219,246,186)'
					],
					extra: {
						ring: {
							borderWidth: 1,
							ringWidth: 30,
						}
					},
					legend: {
						position: 'bottom'
					},
					// dataLabel: false
				},
				pieChartData: {
					series: [{
						data: []
					}]
				},

				option1: [{
						text: '今日',
						value: '5'
					},
					{
						text: '本周',
						value: '6'
					},
					{
						text: '本月',
						value: '7'
					},
					{
						text: '本年',
						value: '8'
					},
				],
				option2: [{
					text: '筛选',
					value: 'a'
				}, ],
				value1: '5',
				value2: 'a',
				lineOpts: {
					color: ['rgb(202,53,50)'],
					legend: {
						show: false
					},
					"xAxis": {
						axisLineColor: 'rgb(229,229,229)',
						fontColor: 'rgb(153,153,153)',
					},
					"yAxis": {
						gridColor: 'rgb(229,229,229)',
						data: [{
							fontColor: 'rgb(153,153,153)',
							axisLine: false,

						}],
						gridType: 'solid'
					},
					"extra": {
						"line": {
							"type": "curve",
							"width": 1
						},
					}
				},
				tableData: [],
				dates: [{
						label: '今日',
						value: '5'
					},
					{
						label: '本周',
						value: '6'
					},
					{
						label: '本月',
						value: '7'
					},
					{
						label: '本年',
						value: '8'
					},
				],
				dateActive: '5',
				show: false,
				venuelist: [], //场馆列表
				itemChooselist: {}, // 场馆数据
				itemChoose: {},
				showlist: true,
				nac: '5',
				after_sale_num: '',
				complete_num: '',
				total_num: '',
			}
		},
		onLoad() {
			if (uni.getStorageSync("entry_name") == '') {
				uni.showToast({
					title: '请登录！',
					icon: 'exception',
					duration: 850
				});
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/my-center/my-center'
					})
				}, 1000);
			}
			var data = uni.getStorageSync("wqzdy");
			var items = JSON.parse(data)
			this.venuelist = items
			this.itemChooselist = this.venuelist[0]
			this.stat_order()
			this.top_sale()
			this.order()
		},
		methods: {
			// 订单类型分析
			async stat_order() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
					sourceTab: this.nac
				};
				let res = await personal.stat_order(params);
				if (res.code == 1) {
					this.pieChartData.series = res.data.series
					this.ringopts.subtitle.name = res.data.total_num
					// uni.hideLoading();
				}
			},
			// 产品热销排行
			async top_sale() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
					sourceTab: this.nac
				};
				let res = await personal.top_sale(params);
				if (res.code == 1) {
					this.tableData = res.data.data
					// uni.hideLoading();
				}
			},
			// 订单数量统计
			async order() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
					sourceTab: this.nac
				};
				let res = await personal.order(params);
				if (res.code == 1) {
					this.total_num = res.data.total_num
					this.complete_num = res.data.complete_num
					this.after_sale_num = res.data.after_sale_num
					// uni.hideLoading();
				}
			},
			dataslist(item) {
				this.pieChartData.series = ''
				this.dateActive = item.value
				this.nac = item.value
				this.stat_order()
				this.top_sale()
				this.order()
			},
			onChange({
				detail: {
					index
				}
			}) {
				this.tabActive = index;
			},
			// 选择场馆
			onChange(e) {
				let that = this
				let i = e.detail
				const item = this.venuelist[i]
				if (item) {
					this.itemChoose = item
					this.venuelist[i].checked = true
				} else {
					this.itemChoose = {}
				}
			},
			onChangelist(item) {
				this.itemChoose = item
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.dateActive = '5'
				this.nac = '5'
				this.stat_order()
				this.top_sale()
				this.order()
			},
			// 确认按钮
			queren() {
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.dateActive = '5'
				this.nac = '5'
				this.stat_order()
			},
			show_no() {
				this.show = true
				this.showlist = false
			},
			showclose() {
				this.show = false
				this.showlist = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.category-orders {
		// padding-bottom: 40rpx;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		background-color: rgb(243, 243, 243);

		.con-1 {
			width: 100%;
			position: relative;

			/deep/ .nav-bar {
				position: fixed;
				z-index: 999;
			}

			.bg {
				width: 100%;
				height: 300rpx;
				background-image: url("https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/5d1ccc3b7ac6cc185130c88a8ac2e90b1eeba707.png");
				background-size: 100%;
				background-position: 50% 80%;
				position: fixed;
				z-index: 9;

				.address {
					color: #fff;
					padding-top: 190rpx;
					padding-right: 30rpx;
					padding-left: 30rpx;
					height: 150rpx;

					&-name {
						font-size: 34rpx;
						font-weight: 700;
						line-height: 34rpx;
					}

					&-desc {
						margin-top: 18rpx;
						font-size: 22rpx;
						line-height: 22rpx;
					}

					.exchange {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
						background-color: rgba(0, 0, 0, 0.2);
						color: rgb(234, 248, 248);
						font-size: 24rpx;
					}
				}
			}
		}

		.dates {
			color: rgb(136, 136, 136);
			font-size: 28rpx;
			margin-top: 300rpx;

			.date-item {
				padding: 30rpx 0;
			}

			.active {
				color: rgb(51, 51, 51);
				font-weight: 700;
			}
		}

		.con-3 {
			width: 100%;
			height: 80rpx;
			background-color: #f8f8f8;
			color: rgb(51, 51, 51);
			font-size: 28rpx;
			font-weight: 700;

			.con-3_left {
				float: left;
				line-height: 80rpx;
				margin-left: 29rpx;
			}

			.con-3_right {
				float: right;
				line-height: 80rpx;
				color: rgb(90, 101, 255);
				margin-right: 29rpx;
			}
		}

		/deep/ .good-box {
			height: 60vh;
			padding: 0px 30rpx;
			display: flex;
			flex-direction: column;

			.title {
				color: #000;
				font-size: 30rpx;
				font-weight: 700;
				margin-top: 40rpx;
			}

			.van-radio__label {
				line-height: inherit;
			}

			.good-list {
				flex: 1;
				height: 0;
				overflow: auto;

				.good-item {
					margin-top: 30rpx;

					.info {
						margin-left: 25rpx;

						.address {
							color: #fff;
							padding-top: 20rpx;
							padding-right: 30rpx;
							height: 70rpx;

							&-name {
								font-size: 34rpx;
								font-weight: 700;
								line-height: 34rpx;
							}

							&-desc {
								margin-top: 18rpx;
								font-size: 22rpx;
								line-height: 22rpx;
							}

							.exchange {
								width: 100rpx;
								height: 100rpx;
								border-radius: 50%;
								background-color: rgba(0, 0, 0, 0.2);
								color: rgb(234, 248, 248);
								font-size: 24rpx;
							}
						}

						.name {
							color: rgb(51, 51, 51);
							font-size: 30rpx;
							font-weight: 500;
							margin-bottom: 10rpx;
						}


						.tag {
							color: rgb(4, 179, 90);
							font-size: 24rpx;
							font-weight: 500;
							padding: 0px 10rpx;
							margin-right: 20rpx;
							background-color: rgba(4, 179, 90, 0.2);
							border-radius: 4rpx;

							&:nth-of-type(2) {
								color: rgb(236, 70, 246);
								background-color: rgba(236, 70, 246, 0.2);
							}
						}

						.address {
							margin-top: 10rpx;
							color: rgb(136, 136, 136);
							font-size: 22rpx;
						}
					}

				}
			}

			.footer {
				padding: 20rpx 0;
				background-color: rgb(255, 255, 255);

				.btn {
					color: rgb(255, 255, 255);
					font-size: 30rpx;
					font-weight: 700;
					padding: 20rpx 0;
					text-align: center;
					background-image: linear-gradient(0deg, rgb(99, 93, 247) 0%, rgb(165, 173, 246) 100%);
					border-radius: 60rpx;
				}
			}
		}

		/deep/.van-dropdown-menu {
			box-shadow: none;
			height: 80rpx;
		}

		.data-stat {
			background-color: rgb(248, 248, 248);
			padding: 30rpx;

			.box {
				background-color: rgb(255, 255, 255);
				border-radius: 4rpx;
				height: 160rpx;

				.value {
					font-size: 50rpx;
					font-weight: 700;
					line-height: 36rpx;
				}

				.label {
					color: rgb(102, 102, 102);
					margin-top: 18rpx;
					font-size: 20rpx;
					font-weight: 500;
					line-height: 20rpx;
				}
			}
		}

		.title {
			font-size: 30rpx;
			font-weight: 700;
			line-height: 29rpx;
			padding: 30rpx;
		}

		.table {
			font-size: 22rpx;

			.thead {
				line-height: 26px;
				background-color: rgb(248, 248, 248);
				color: rgb(153, 153, 153);
			}

			.list-2 {
				width: 100%;
				max-height: 1000rpx;

				.th,
				.td {
					width: 30%;
					border-right: 1px solid rgb(238, 238, 238);
					border-bottom: 1px solid rgb(238, 238, 238);

					&:first-of-type {
						width: 70%;
					}
				}
			}

			.th,
			.td {
				width: 30%;
				border-right: 1px solid rgb(238, 238, 238);
				border-bottom: 1px solid rgb(238, 238, 238);

				&:first-of-type {
					width: 70%;
				}
			}

			.td {
				padding: 20rpx 0;
			}
		}
	}
</style>